<template>
  <div class="ca-box">
    <swiper ref="swiper" :options="swiperOption2">
      <swiper-slide class="each-banner" v-for="item in caseList" :key="item.id">
        <div class="eachca">
          <div class="left">
            <img :src="item.cover" alt />
          </div>
          <div class="right">
            <div class="title">{{ item.title }}</div>
            <div class="dian"></div>
            <div class="background">
              <span>项目背景:</span>
              <span :title="item.remark1">{{ item.remark1 }}</span>
            </div>
            <div class="introduce">
              <span>项目介绍:</span>
              <span :title="item.remark2">{{ item.remark2 }}</span>
            </div>
            <div class="target">
              <span>项目目标:</span>
              <span :title="item.remark3">{{ item.remark3 }}</span>
            </div>
            <div class="show-more" @click="showDetail(item)">
              <span>详情</span>
              <img src="../../public/static/pAnds/jiantou-small@2x(1).png" alt="了解更多" />
            </div>
          </div>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
    <div class="pc-dialog">
      <el-dialog :title="detail.title" :visible.sync="isShowPcDetail" top="5vh" width="15.14rem">
        <div class="conten-body content quill-editor">
          <div class="ql-editor" v-html="detail.content"></div>
        </div>
      </el-dialog>
    </div>
    <div class="mo-dialog">
      <el-dialog :title="detail.title" :visible.sync="isShowMoDetail" top="2vh" width="7rem">
        <div class="conten-body content quill-editor">
          <div class="ql-editor" v-html="detail.content"></div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
export default {
  name: "case",
  props: {
    caseList: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      swiperOption2: {
        spaceBetween: 30,
        // loop: true,
        centeredSlides: true,
        autoplay: {
          delay: 3000,
          disableOnInteraction: false
        },
        observer: true, //修改swiper自己或子元素时，自动初始化swiper
        observeParents: true, //修改swiper的父元素时，自动初始化swiper
        pagination: {
          el: ".swiper-pagination",
          clickable: true
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev"
        }
      },
      isShowPcDetail: false,
      isShowMoDetail: false,
      winWidth: "",
      detail: {
        title: "",
        content: ""
      }
    };
  },
  methods: {
    showDetail(item) {
      this.detail.title = item.title;
      if (this.winWidth > 1000) {
        this.isShowPcDetail = true;
      } else {
        this.isShowMoDetail = true;
      }
      this.$post("/v1/product/demo/info", { did: item.did }).then(res => {
        if (res.code == 200) {
          const { data } = res;
          let that = this;
          this.detail.content = data.demo.content;
        }
      });
    }
  },
  mounted() {
    var winWidth = window.innerWidth;
    this.winWidth = winWidth;
    let that = this;
    this.$refs.swiper.$swiper.on("slideChangeTransitionStart", function() {
      that.$parent.getIndex(this.activeIndex);
    });
  }
};
</script>
<style lang="less" scoped>
.ca-box {
  width: 15.15rem;
  margin: 0 auto;
  .eachca {
    display: flex;
    margin-bottom: 0.8rem;
    .left {
      width: 7.39rem;
      height: 6.18rem;
      img {
        width: 100%;
        height: 100%;
        vertical-align: middle;
      }
    }
    .right {
      width: 7.75rem;
      box-sizing: border-box;
      height: 6.18rem;
      background: rgba(0, 0, 0, 0.6);
      padding: 0.7rem 0.56rem;
      color: #fff;
      text-align: left;
      position: relative;
      .title {
        font-size: 0.3rem;
        margin-bottom: 0.2rem;
        line-height: 0.4rem;
      }
      .dian {
        width: 0.35rem;
        height: 0.06rem;
        background: #ffffff;
        border-radius: 0.03rem;
        margin-bottom: 0.41rem;
      }
      .background,
      .introduce,
      .target {
        font-size: 0.18rem;
        line-height: 0.36rem;
        margin-bottom: 0.1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }

      .show-more {
        position: absolute;
        bottom: 0.5rem;
        cursor: pointer;
        font-size: 0.18rem;
        display: flex;
        align-items: center;
        width: 1rem;
        height: 0.4rem;
        border: 1px solid #fff;
        border-radius: 0.5rem;
        padding: 0.06rem 0.18rem;
        text-align: center;
        justify-content: space-around;
        z-index: 33;
        img {
          width: 0.36rem;
          height: 0.09rem;
          vertical-align: middle;
        }
      }
    }
  }
}
/deep/.swiper-pagination-bullet {
  background: #fff;
}
/deep/.el-dialog__header {
  height: 0.8rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  line-height: 0.8rem;
  display: flex;
  align-items: center;
}
/deep/.el-dialog__title {
  display: inline-block;
  width: 100%;
  text-align: center;
}
/deep/.el-dialog__body {
  overflow-y: auto;
}
.conten-body {
  height: 9rem;
}
@media screen and (max-width: 1000px) {
  .ca-box {
    width: 6.82rem;
    margin: 0 auto;
    .eachca {
      width: 6.82rem;
      flex-wrap: wrap;
      .left {
        width: 100%;
      }
      .right {
        width: 100%;
      }
    }
  }
}
</style>